<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
<head>
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta charset="UTF-8">
<title>用户中心-修改登录密码</title>
<script src="/v3/js/jquery-1.10.2.min.js" type="text/javascript"></script>
<link type="text/css" rel="stylesheet" href="/v3/css/wstyle.css">
<link type="text/css" rel="stylesheet" href="/v3/css/account.css">
</head>
<style>
.surePw .login_input {
	margin-top: 10px;
}

.change-passwd {
	padding: 30px 10px 0;
}

.input-box {
	padding: 0;
	width: 100%;
}

.login_input {
	margin-top: 0;
	float: left;
}

.mdfPw {
	float: left;
	margin-bottom: 20px;
	width: 100%;
}

.mdfPw .in_put {
	padding: 5px 10px;
}

.getPW {
	float: right;
	margin: 0 0 0 10px;
	width: 95px;
}

.getPW a {
	height: 30px;
	line-height: 30px;
	width: 95px;
	padding: 5px 0;
	text-align: center;
}

.r_line {
	line-height: 26px;
	text-align: center;
}

.link-touch {
	border: none;
	position: static;
}

.link-touch .txt {
	float: none;
	width: 100%;
}

.link-touch .errs {
	padding: 10px 0 0;
	clear: both
}
</style>
<body>
	<div id="wrap">
		<div class="change-passwd">
			<div class="login_input auth_code" style="margin-bottom:20px;">
				<div class="r_line">
					<label class="txt">验证码</label>
				</div>
				<div class="in_put">
					<input placeholder="请输入验证码" type="text" id="authCode"
						name="paramMap.code" class="input" style="width:65%" maxlength="4">
					<img src="I4008lOve893gOfUll983/imageCode.do?pageId=modifyLoginPwd"
						title="点击更换验证码" style="cursor: pointer;" id="imgverCode"
						onclick="switchCode('modifyLoginPwd');" width="104" alt="验证码"
						title="验证码" class="verifycode">
				</div>
			</div>
			<div class="link-touch mdfPw">
				<div class="input-box">
					<div class="login_input">
						<div class="r_line">
							<label class="txt">动态码</label>
						</div>
						<div class="in_put">
							<input id="mobile" name="mobile" type="hidden"
								value="${sessionScope.user.mobilePhone}"> <input
								placeholder="请输入动态码" id="captcha" name="captcha" maxlength="16"
								onkeydown="if(event.keyCode==13){checkPassword();}"
								type="number">
						</div>
					</div>
					<div class="getPW">
						<a id="getAutoPwdBtn" href="javascript:getAutoPwd();">获取动态码</a>
					</div>
				</div>
			</div>
			<div class="link-touch surePw">
				<div class="input-box">
					<div class="login_input">
						<div class="r_line">
							<label class="txt">新密码</label>
						</div>
						<div class="in_put">
							<input placeholder="请输入新密码" id="newPwd" name="newPwd"
								maxlength="16" type="password">
						</div>
					</div>
					<div class="login_input">
						<div class="r_line">
							<label class="txt">确认密码</label>
						</div>
						<div class="in_put">
							<input placeholder="请再次输入新密码" id="confirmnewPwd"
								name="confirmnewPwd" maxlength="16" type="password">
						</div>
					</div>
				</div>
				<div id="errorTip" class="vtip errs"></div>
			</div>

		</div>
		<div class="Nxt-btn">
			<a href="javascript:modifyLoginPassword();">修改密码</a>
		</div>
	</div>
	<jsp:include page="/include/v3/footer.jsp"></jsp:include>
	<script type="text/javascript" src="/v3/js/showts.js"></script>
	<script type="text/javascript">
$(window).load(function() {
	var ibW = $(".mdfPw .input-box").width();
	var rW = $(".mdfPw .r_line").width();
	var pwW = $(".mdfPw .getPW").width();	
	$(".mdfPw .login_input").width(ibW-pwW-15);
	$(".mdfPw .in_put").width((ibW-pwW-15)-rW-22);
	var rlW = $(".surePw .r_line").width();
	var lW = $(".surePw .login_input").width();
	$(".surePw .in_put").width(lW-rlW-32);
	$(window).resize(function() {
		myWindowResize();
	})
	function myWindowResize() {
	var ibW = $(".mdfPw .input-box").width();
	var rW = $(".mdfPw .r_line").width();
	var pwW = $(".mdfPw .getPW").width();	
	$(".mdfPw .login_input").width(ibW-pwW-15);
	$(".mdfPw .in_put").width((ibW-pwW-15)-rW-22);
	var rlW = $(".surePw .r_line").width();
	var lW = $(".surePw .login_input").width();
	$(".surePw .in_put").width(lW-rlW-32);
	}
});
    function confirmPsd(value){
    	if (value == null || value == '') {
    		$("#pwdErrorTip").html('请输入动态码').show();
        	return false;
    	}else{
    		return true;
    	}
    }
    
    function isOldSameToNew(){
    	if($("#pwd").val() == $("#newPwd").val()){
    		$("#errorTip").html("新密码与现在密码不能相同").show();
    		return false;
    	}
    	else{
    		return true;
    	}
    }
    
    function confirmSame(){
    	if($("#newPwd").val() == $("#confirmnewPwd").val()){
    		return true;
    	}else{
    		$("#errorTip").html("两次新密码不一致").show();
    		return false;
    	}   	
    }
    
    function invalidate(){
    	if(confirmPsd($("#captcha").val()) && confirmPsd( $("#newPwd").val()) && confirmPsd($("#confirmnewPwd").val()) && isOldSameToNew() && confirmSame()){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    function modifyLoginPassword(){
    	if(invalidate()){
    		var param = {};
            param["paramMap.captcha"] = $("#captcha").val();
            param["paramMap.newPassword"] = $("#newPwd").val();
            param["paramMap.confirmPassword"] = $("#confirmnewPwd").val();
    		$.ajax({
    			type:'POST',
    			url: "/updateLoginPsdWithNoForward.do",
    			data: param,
    			success: function(data){
    				if(data.code == 1){
    					window.location.href="/modifyLoginPwdSuccess.do";
    				}else if(data.code <=0){
    					$("#errorTip").html(data.msg).show();
    				}else{
    					$("#errorTip").html("登录密码更新出错,请重新修改").show();
    				}
    			},
    			error: function(data){
    				$("#errorTip").html("登录密码更新出错,请重新修改").show();
    			} 
    		});
    	}
    }
function getAutoPwd() {
var vCode = $("#authCode").val();
	if (vCode == "" || vCode == null) {
			$("#errorTip").html("请输入验证码").show();
			return;
	}
	if($("#getAutoPwdBtn").hasClass("disable-bt")){
		return;
	}
	$("#pWord").removeClass().addClass("icon-pWord2");
	var param = {};
    param["paramMap.pageId"] = "modifyLoginPwd";
    param["paramMap.mobile"] = $("#mobile").val();
    param["paramMap.authCode"] = $("#authCode").val();
	$.ajax({
		type: 'POST',
		url: "/getAutoPwd.do",
		data: param,
		success: function(data) {
			//错误等信息提示
			if(data.code == "failed"){
				$("#errorTip").html(data.msg).show();
				return;
			}
			if(data.code == "errorCode"){
				$("#errorTip").html(data.msg).show();
				switchCode('modifyLoginPwd');
				return;
			}
			//倒计时
			_interval = setInterval("autoPwdSend()", 1000);
		}
	});
}

/**
 * 60秒计时
 */
var n = 60;
/**
 * 连续执行方法句柄
 */
var _interval;
/**
 * 发送动态密码循环执行方法
 */
function autoPwdSend(){
	n--;
	//获取验证码按钮 不可用
	$("#getAutoPwdBtn").addClass("disable-bt");
    $("#getAutoPwdBtn").attr("href","javascript:;").html(n + "秒后可重发");
	
	if (n == 0) {
	    $("#getAutoPwdBtn").removeClass("disable-bt");
	    $("#getAutoPwdBtn").attr("href","javascript:getAutoPwd();").html("获取动态码");
		clearInterval(_interval);
		n = 60;
	}
}
function switchCode(str) {
	var timenow = new Date();
	$("#imgverCode").attr("src","I4008lOve893gOfUll983/imageCode.do?pageId="+str+"&d="+ timenow);
}	
</script>
</body>
</html>
